<?php
/**
 * Created by PhpStorm.
 * User: This
 * Date: 2018/11/27
 * Time: 22:53
 */
namespace app\admin\model;
use think\Model;

class Menus extends Model{
    /**
     * @param $condition
     * @param $num
     * @param string $field
     * @return \think\Paginator
     * @throws \think\exception\DbException
     */
    public function getPage($condition,$field = '*',$num = 10){
        return $this->name('menu')->field($field)->cache(true)->where($condition)->paginate($num);
    }

    /**
     * @param $condition
     * @param string $field
     * @return array|false|\PDOStatement|string|Model
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function getOne($condition,$field= '*'){
        return $this->name('menu')->field($field)->where($condition)->find();
    }
    /**
     * @param $condition
     * @return int
     */
    public function del($condition){
        return $this->name('menu')->where($condition)->delete();
    }

    /**
     * @param $data
     * @return int|string
     */
    public function add($data){
        return $this->name('menu')->insert($data);
    }

    /**
     * @param $condition
     * @param $data
     * @return $this
     */
    public function edit($condition,$data){
        return $this->name('menu')->where($condition)->update($data);
    }
}